package com.zzh.phone.hviews;


import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.google.android.material.badge.BadgeDrawable;
import com.google.android.material.badge.BadgeUtils;
import com.zzh.lib.click.OnButtonClickListener;
import com.zzh.lib.core.listener.HOnClickListener;
import com.zzh.lib.core.utils.HDateUtils;
import com.zzh.lib.core.utils.LogUtils;
import com.zzh.lib.views.adapter.BaseBannerAdapter;
import com.zzh.lib.views.adapter.holder.HSuperViewHolder;
import com.zzh.mvvm.base.BaseRabbitActivity;
import com.zzh.phone.hviews.databinding.ActBadgeViewBinding;
import com.zzh.phone.hviews.listener.OnExButtonClickListener;
import com.zzh.phone.hviews.vm.BadgeViewModel;

import java.util.ArrayList;
import java.util.Arrays;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

/**
 * Created by ZZH on 2022/7/30.
 *
 * @Date: 2022/7/30
 * @Email: zzh_hz@126.com
 * @QQ: 1299234582
 * @Author: zzh
 * @Description:
 */
public class BadgeViewAct extends BaseRabbitActivity<BadgeViewModel, ActBadgeViewBinding> {
    @Override
    protected void initViewAndData(Bundle savedInstanceState) {
        bind.hbvp.setVisibility(View.GONE);
        bind.hbvp.setAdapter(new BaseBannerAdapter() {
            @Override
            protected void bindData(HSuperViewHolder holder, Object data, int position, int pageSize) {

                ImageView view = holder.getView(R.id.aiv_img);
                Glide.with(view).load(data.toString()).into(view);

            }

            @Override
            public int getLayoutId(int viewType) {
                return R.layout.item_img;
            }
        }).create(Arrays.asList("https://t7.baidu.com/it/u=727460147,2222092211&fm=193&f=GIF", "https://t7.baidu.com/it/u=2511982910,2454873241&fm=193&f=GIF"));

        bind.sivDelivery.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                BadgeDrawable badgeDrawable = BadgeDrawable.create(BadgeViewAct.this);
                badgeDrawable.setNumber(100);
                badgeDrawable.setMaxCharacterCount(3);
                badgeDrawable.setBackgroundColor(Color.RED);
                badgeDrawable.setBadgeGravity(BadgeDrawable.TOP_END);
                badgeDrawable.setVisible(true);
                BadgeUtils.attachBadgeDrawable(badgeDrawable, bind.sivDelivery, bind.rlSivDelivery);
                bind.sivDelivery.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
        });
        bind.mtvText.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                BadgeDrawable badgeDrawable = BadgeDrawable.create(BadgeViewAct.this);
                badgeDrawable.setNumber(100);
                badgeDrawable.setMaxCharacterCount(3);
                badgeDrawable.setBackgroundColor(Color.RED);
                badgeDrawable.setBadgeGravity(BadgeDrawable.TOP_END);
                badgeDrawable.setVisible(true);
                BadgeUtils.attachBadgeDrawable(badgeDrawable, bind.mtvText);
                bind.mtvText.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
        });

        bind.siv.setOnClickListener(new OnExButtonClickListener(bind.siv, new HOnClickListener() {
            @Override
            public void onSafeClick(View v) {
                LogUtils.e("--------------: " + System.currentTimeMillis());
            }
        }));


    }

    @Override
    protected int initVariableId() {
        return BR.viewModel;
    }
}
